from flask import Flask
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
manager = Manager(app)

app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:mysql@127.0.0.1:3306/Migrate_test"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
app.config[" "] = "pass"
db = SQLAlchemy(app)

# 第一个参数实例
migrate = Migrate(app, db)

# 添加一个db指令
manager.add_command('db', MigrateCommand)


# 定义role模型
class Role(db.Model):
    __tablename__ = 'roles'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    user = db.relationship('User', backref='role')

    def __repr__(self):
        return 'Role:' .format(self.name)


# 定义用户
class User(db.Model):
    __talbe__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True, index=True)
    # 外键
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))

    def __repr__(self):
        return "User:" .format(self.username)


@app.route('/')
def index():
    pass

if __name__ == '__main__':
    manager.run()
